//-----------------------------------------------------------------------
// <copyright file="StringUtil.cs" company="Pyramid Consulting">
//     Copyright (c) Pyramid Consulting. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace Bamboo.Core.Common
{
    public class StringUtil
    {
        /// <summary>
        /// Filter all text to prevent cross site scripting hack
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public static string FilterTextPreventCrossiteHack(string content)
        {
            string result = content;
            if (result == null)
            {
                result = "";
            }
            Regex regEx = new Regex(@"<script([^>]*)>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            result = regEx.Replace(result, "");
            regEx = new Regex(@"</script([^>]*)>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            result = regEx.Replace(result, "");
            return result;
        }
        /// <summary>
        /// Remove all Html tag in a string
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public static string RemoveAllHtmlTag(string content)
        {
            string result = content;
            string[] removeTagArray = new string[] { "b", "a", "script", "i", "ul", "li", "ol", "font", "span", "div", "u" };
            foreach (string removeTag in removeTagArray)
            {
                string regExpressionToRemoveBeginTag = string.Format("<{0}([^>]*)>", removeTag);
                Regex regEx = new Regex(regExpressionToRemoveBeginTag, RegexOptions.IgnoreCase | RegexOptions.Compiled);
                result = regEx.Replace(result, "");

                string regExpressionToRemoveEndTag = string.Format("</{0}([^>]*)>", removeTag);
                regEx = new Regex(regExpressionToRemoveEndTag, RegexOptions.IgnoreCase | RegexOptions.Compiled);
                result = regEx.Replace(result, "");
            }
            return result;
        }

        
    }
}
